import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class addJFrame extends JFrame {

    public addJFrame() {
        this.setTitle("添加收货信息");
        this.setSize(500, 300);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setAlwaysOnTop(true);//置顶
        this.setLayout(null);

        // 创建姓名、电话和收货地址的 JLabel 和 JTextField
        JLabel nameLabel = new JLabel("姓名：");
        JTextField nameField = new JTextField();
        JLabel phoneLabel = new JLabel("电话：");
        JTextField phoneField = new JTextField();
        JLabel addressLabel = new JLabel("收货地址：");
        JTextField addressField = new JTextField();

        // 设置组件的位置和大小
        nameLabel.setBounds(50, 50, 100, 30);
        nameField.setBounds(150, 50, 200, 30);
        phoneLabel.setBounds(50, 100, 100, 30);
        phoneField.setBounds(150, 100, 200, 30);
        addressLabel.setBounds(50, 150, 100, 30);
        addressField.setBounds(150, 150, 200, 30);

        // 创建确定按钮
        JButton okButton = new JButton("确定");
        okButton.setBounds(200, 200, 100, 30);

        // 设置确定按钮的点击事件监听器
        okButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 点击按钮时只关闭当前界面
                dispose();

            }
        });

        // 将组件添加到 JFrame
        this.add(nameLabel);
        this.add(nameField);
        this.add(phoneLabel);
        this.add(phoneField);
        this.add(addressLabel);
        this.add(addressField);
        this.add(okButton);

        // 设置窗口可见
        this.setVisible(true);
    }
}
